package com.fly.controller;

import com.fly.bean.SystemProperties;
import com.fly.bean.SystemPropertiesValue;
import com.fly.service.SysProService;
import com.fly.util.Msg;
import com.fly.vo.SysProValueVo;
import com.fly.vo.SysPro_lmg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/syspro")
public class SysProController {

    @Autowired
    SysProService sysProService;

    /**
     * 获取所有配置数据
     * @return
     */
    @RequestMapping("/getAllSysPro")
    @ResponseBody
    public Msg getAllSysPro(){

        List<SystemProperties> systemProperties = sysProService.getAllSysPro();

        return Msg.success().add("sysPro",systemProperties);
    }

    @RequestMapping("/getAllSysProl")
    @ResponseBody
    public Msg getAllSysProL(){

        List<SysPro_lmg> systemProperties = sysProService.getAllSysProl();

        return Msg.success().add("sysPro",systemProperties);
    }

    /**
     * 添加系统配置
     * @param systemPropertie
     * @return
     */
    @RequestMapping("/addSysPro")
    @ResponseBody
    public Msg insertSysPro(SystemProperties systemPropertie){
        return addSys(systemPropertie);
    }

    /**
     * 添加系统配置参数
     * @param SystemPropertiesValue
     * @return
     */
    @RequestMapping("/addSysProValue")
    @ResponseBody
    public Msg insertSysProValues(SysProValueVo SystemPropertiesValue){

        if (SystemPropertiesValue.getSysProValueName()==null|SystemPropertiesValue.getSysProId()==null) {

            return Msg.fail().add("flag","数据不全");
        }else {
            int f = sysProService.insertSysProValues(SystemPropertiesValue.getSysProId(),SystemPropertiesValue.getSysProValueName());
            return Msg.success().add("flag",f);
        }

    }

    /**
     * 改变启用状态
     * @param systemProperties
     * @return
     */
    @RequestMapping("/changeSysProState")
    @ResponseBody
    public Msg updateSysProState(SystemProperties systemProperties){

        int f =  sysProService.updateSysProState(systemProperties);

        return Msg.success().add("flag",f);
    }

    /**
     * 添加或修改系统配置
     * @param systemProperties
     * @return
     */
    @RequestMapping("/addchangeSysPro")
    @ResponseBody
    public Msg updateProSys(SystemProperties systemProperties){
        if (systemProperties.getSysProId()==null||systemProperties.getSysProId()<=0){
            return addSys(systemProperties);
        }else {
            int f = sysProService.updateSysPro(systemProperties);
            return Msg.success().add("flag",f);
        }
    }

    /**
     * 添加sysPro配置
     * @param systemPropertie
     * @return
     */
    public Msg addSys(SystemProperties systemPropertie){
        if (systemPropertie.getSysProName()!=null&&systemPropertie.getSysProTypeCode()!=null&&systemPropertie.getSysProDescribe()!=null&&
                systemPropertie.getSysProState()==0||systemPropertie.getSysProState()==1) {
            int f = sysProService.insertSysPro(systemPropertie);
            return Msg.success().add("flag",f);
        }else {
            return Msg.fail().add("flag","数据不全或不正确");
        }
    }

}
